<?php
require_once dirname(__FILE__).'/UserDao.php';

class UserService {
    private $dao;
    
    public function __construct() {
        $this->dao = new UserDao();
    }

    public function auth($loginname, $password) {
        $user = $this->dao->getUserByLoginname($loginname);
        if ($user['password'] != $password) {
            return 1;
        }
        date_default_timezone_set('Asia/Shanghai');
        if (isset($user) && $user['status'] == 'active') {
            $now = time();
//             if (!empty($user['valid_from']) && $now >= strtotime($user['valid_from'])) {
//                 return 3;
//             }
            if (!empty($user['valid_to']) && $now > strtotime($user['valid_to'])) {
                return 4;
            }
        } else {
            return 2;
        }
        return 0;
    }
    
    public function getUserByLoginname($loginname) {
        $user = $this->dao->getUserByLoginname($loginname);
        return $user;
    }
}
?>